package net.fiodor.log.channel {
	import net.fiodor.log.LogLevel;	
	import net.fiodor.log.LogEvent;
	import net.fiodor.log.channel.AbstractChannel;
	import net.fiodor.log.channel.IChannel;	

	/**
	 * @author Tomasz Swierszcz, 
	 * email: tomasz.swierszcz@dreamlab.pl
	 */
	public class FlashDebugChannel extends AbstractChannel implements IChannel {
		public function FlashDebugChannel() {
			super();
		}

		public function publish(e : LogEvent) : void {
		
			var messageToLog : Object = e.argument;
			var typeOf : String = typeof( messageToLog );
			if( typeOf != "string" ) {
				Debug.traceObject(messageToLog, 10, resolveFlashDebugPanelLogLevel(e.level), 5);							
			}
		
			else Debug.trace(e, resolveFlashDebugPanelLogLevel(e.level));
		}

		private function resolveFlashDebugPanelLogLevel( logLevel : LogLevel ) : Number {
		
			switch( logLevel ) {
			
				case LogLevel.INFO : 
					return Debug.INFO;
				case LogLevel.WARN : 
					return Debug.WARN;
				case LogLevel.ERROR : 
					return Debug.ERROR;
				case LogLevel.FATAL : 
					return Debug.FATAL;
			}	
		
			return Debug.DEBUG;
		}
	}
}
